/**
 * This file is part of Virtual Environment Tutoring Engine (VETE).
 * Copyright (C) 2011 Iowa State University.
 *
 * VETE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/
 
import java.util.ArrayList;

public class State {

	String stateName;
	int stateKind; // 0 -> atomic; 1 -> complex 
	int stateType; // 0 -> Start; 1 -> Intermediate; 2 -> Failed; 3 -> Goal
	int statePriority;
	
	EntitySet entitySet;

	ArrayList<String> hintList;
	ArrayList<String> JITList;
	ArrayList<String> promptList;	
	
	String getName() {
		return this.stateName;
	}
	
	int getType() {
		return this.stateType;
	}
	
	int getPriority() {
		return this.statePriority;
	}
	
	int getKind() {
		return this.stateKind;
	}
	
	String getHint(int i) {
		return hintList.get(i);
	}
	
	String getJIT(int i) {
		return JITList.get(i);
	}
	
	String getPrompt(int i) {
		return promptList.get(i);
	}
	
	State(String sName, int sPriority, int sKind, int sType, ArrayList<String> hList, ArrayList<String> JList, ArrayList<String> pList, EntitySet l_entitySet) {
		this.stateName = sName;
		this.statePriority = sPriority;
		this.stateKind = sKind;
		this.stateType = sType;
		this.hintList = hList;
		this.JITList = JList;
		this.promptList = pList;		
		this.entitySet = l_entitySet;
	}
	
	void printDetails() {
		System.out.println("Name: "+getName());
		System.out.println("Priority: "+getPriority());
		System.out.println("Type: "+getType());
		System.out.println("Kind: "+getKind());
		
		System.out.println(entitySet.soldierList.get(0).getEntityID());
		System.out.println("Health: " + entitySet.soldierList.get(0).getHealth());
		System.out.println("Location: (" + entitySet.soldierList.get(0).getLocation()[0] + ", " + entitySet.soldierList.get(0).getLocation()[1] + ", " + entitySet.soldierList.get(0).getLocation()[2] + ")");
		System.out.println("Action: " + entitySet.soldierList.get(0).getAction());
		
		System.out.println(entitySet.insurgentList.get(0).getEntityID());
		System.out.println("Health: " + entitySet.insurgentList.get(0).getHealth());
		System.out.println("Location: (" + entitySet.insurgentList.get(0).getLocation()[0] + ", " + entitySet.insurgentList.get(0).getLocation()[1] + ", " + entitySet.insurgentList.get(0).getLocation()[2] + ")");
		System.out.println("Action: " + entitySet.insurgentList.get(0).getAction());
		
		System.out.println(entitySet.civilianList.get(0).getEntityID());
		System.out.println("Health: " + entitySet.civilianList.get(0).getHealth());
		System.out.println("Location: (" + entitySet.civilianList.get(0).getLocation()[0] + ", " + entitySet.civilianList.get(0).getLocation()[1] + ", " + entitySet.civilianList.get(0).getLocation()[2] + ")");
		System.out.println("Action: " + entitySet.civilianList.get(0).getAction());
		
		System.out.println(entitySet.bombList.get(0).getEntityID());
		System.out.println("Location: (" + entitySet.bombList.get(0).getLocation()[0] + ", " + entitySet.bombList.get(0).getLocation()[1] + ", " + entitySet.bombList.get(0).getLocation()[2] + ")");
		System.out.println("Diffused?: " + entitySet.bombList.get(0).isDiffused());
		System.out.println("Exploded?: " + entitySet.bombList.get(0).isExploded());		
	}
	
	boolean stateCompare(State S2) {
		EntitySet a = this.entitySet;
		EntitySet b = S2.entitySet;
		if( a.soldierList.size()!=b.soldierList.size() || a.insurgentList.size()!=b.insurgentList.size() || a.civilianList.size()!=b.civilianList.size() || a.bombList.size()!=b.bombList.size())
			return false;
		for(int i=0; i<b.soldierList.size(); i++) {
			if( !a.soldierList.get(i).location[0].equals("DC") && !b.soldierList.get(i).location[0].equals("DC") ) 
				if(!a.soldierList.get(i).location[0].equals(b.soldierList.get(i).location[0]))
					return false;
			if( !a.soldierList.get(i).location[1].equals("DC") && !b.soldierList.get(i).location[1].equals("DC") ) 
				if(!a.soldierList.get(i).location[1].equals(b.soldierList.get(i).location[1]))
					return false;
			if( !a.soldierList.get(i).location[2].equals("DC") && !b.soldierList.get(i).location[2].equals("DC") ) 
				if(!a.soldierList.get(i).location[2].equals(b.soldierList.get(i).location[2]))
					return false;
			if( !a.soldierList.get(i).health.equals("DC") && !b.soldierList.get(i).health.equals("DC") ) 
				if(!a.soldierList.get(i).health.equals(b.soldierList.get(i).health))
					return false;
			if( !a.soldierList.get(i).action.equals("DC") && !b.soldierList.get(i).action.equals("DC") ) 
				if(!a.soldierList.get(i).action.equals(b.soldierList.get(i).action))
					return false;
		}
		for(int i=0; i<b.insurgentList.size(); i++) {
			if( !a.insurgentList.get(i).location[0].equals("DC") && !b.insurgentList.get(i).location[0].equals("DC") ) 
				if(!a.insurgentList.get(i).location[0].equals(b.insurgentList.get(i).location[0]))
					return false;
			if( !a.insurgentList.get(i).location[1].equals("DC") && !b.insurgentList.get(i).location[1].equals("DC") ) 
				if(!a.insurgentList.get(i).location[1].equals(b.insurgentList.get(i).location[1]))
					return false;
			if( !a.insurgentList.get(i).location[2].equals("DC") && !b.insurgentList.get(i).location[2].equals("DC") ) 
				if(!a.insurgentList.get(i).location[2].equals(b.insurgentList.get(i).location[2]))
					return false;
			if( !a.insurgentList.get(i).health.equals("DC") && !b.insurgentList.get(i).health.equals("DC") ) 
				if(!a.insurgentList.get(i).health.equals(b.insurgentList.get(i).health))
					return false;
			if( !a.insurgentList.get(i).action.equals("DC") && !b.insurgentList.get(i).action.equals("DC") ) 
				if(!a.insurgentList.get(i).action.equals(b.insurgentList.get(i).action))
					return false;
		}
		for(int i=0; i<b.civilianList.size(); i++) {
			if( !a.civilianList.get(i).location[0].equals("DC") && !b.civilianList.get(i).location[0].equals("DC") ) 
				if(!a.civilianList.get(i).location[0].equals(b.civilianList.get(i).location[0]))
					return false;
			if( !a.civilianList.get(i).location[1].equals("DC") && !b.civilianList.get(i).location[1].equals("DC") ) 
				if(!a.civilianList.get(i).location[1].equals(b.civilianList.get(i).location[1]))
					return false;
			if( !a.civilianList.get(i).location[2].equals("DC") && !b.civilianList.get(i).location[2].equals("DC") ) 
				if(!a.civilianList.get(i).location[2].equals(b.civilianList.get(i).location[2]))
					return false;
			if( !a.civilianList.get(i).health.equals("DC") && !b.civilianList.get(i).health.equals("DC") ) 
				if(!a.civilianList.get(i).health.equals(b.civilianList.get(i).health))
					return false;
			if( !a.civilianList.get(i).action.equals("DC") && !b.civilianList.get(i).action.equals("DC") ) 
				if(!a.civilianList.get(i).action.equals(b.civilianList.get(i).action))
					return false;
		}
		for(int i=0; i<b.bombList.size(); i++) {
			if( !a.bombList.get(i).location[0].equals("DC") && !b.bombList.get(i).location[0].equals("DC") ) 
				if(!a.bombList.get(i).location[0].equals(b.bombList.get(i).location[0]))
					return false;
			if( !a.bombList.get(i).location[1].equals("DC") && !b.bombList.get(i).location[1].equals("DC") ) 
				if(!a.bombList.get(i).location[1].equals(b.bombList.get(i).location[1]))
					return false;
			if( !a.bombList.get(i).location[2].equals("DC") && !b.bombList.get(i).location[2].equals("DC") ) 
				if(!a.bombList.get(i).location[2].equals(b.bombList.get(i).location[2]))
					return false;
			if( !a.bombList.get(i).diffused.equals("DC") && !b.bombList.get(i).diffused.equals("DC") ) 
				if(!a.bombList.get(i).diffused.toLowerCase().equals(b.bombList.get(i).diffused.toLowerCase()))
					return false;
			if( !a.bombList.get(i).exploded.equals("DC") && !b.bombList.get(i).exploded.equals("DC") ) 
				if(!a.bombList.get(i).exploded.toLowerCase().equals(b.bombList.get(i).exploded.toLowerCase()))
					return false;
		}
		//System.out.println("!!!");
		return true;
	}
}
